package info.wangyuan.agent.controller.admin;

import info.wangyuan.agent.entity.po.ModelConfig;
import info.wangyuan.agent.service.curd.ModelConfigService;
import info.wangyuan.agent.utils.Result;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员模型管理
 *
 * @author Albert
 * @since 2025-07-10 02:00:03
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/admin/model")
public class ModelController {

    private final ModelConfigService modelConfigService;

    public ModelController(ModelConfigService modelConfigService) {
        this.modelConfigService = modelConfigService;
    }

    /**
     * 获取模型列表
     */
    @GetMapping("/list")
    public Result<List<ModelConfig>> getModelList(@RequestParam(required = false) String type) {
        return Result.success(modelConfigService.getModelList(type));
    }

    /**
     * 获取单个模型信息
     */
    @GetMapping("/{modelId}")
    public Result<ModelConfig> getModelInfo(@PathVariable Integer modelId) {
        return Result.success(modelConfigService.getById(modelId));
    }

    /**
     * 添加模型
     */
    @PostMapping("/add")
    public Result<Void> addModel(@RequestBody ModelConfig modelConfig) {
        modelConfigService.canAdd(modelConfig);
        return Result.success();
    }

    /**
     * 修改模型
     */
    @PostMapping("/update")
    public Result<Void> updateModel(@RequestBody ModelConfig modelConfig) {
        modelConfigService.canUpdate(modelConfig);
        return Result.success();
    }

    /**
     * 删除模型
     */
    @DeleteMapping("/delete/{id}")
    public Result<Void> deleteModel(@PathVariable @NotNull Integer id) {
        modelConfigService.canDelete(id);
        return Result.success();
    }

    /**
     * 测试模型健康度
     */
    @GetMapping("/test")
    public Result<String> modelTest() {
        modelConfigService.list().forEach(modelConfigService::modelTest);
        return Result.success("健康状态良好，未发现异常");
    }

}
